package com.huc.rabbit.mq;

import com.huc.rabbit.mq.consumer.ChannelMessageConsumer;
import com.huc.rabbit.mq.provider.ChannelMessageProvider;
import com.huc.rabbit.mq.provider.P2PMessageProvider;
import com.huc.rabbit.mq.provider.PushSubMessageProvider;
//import com.huc.rabbit.mq.provider.TopicMessageProvider;
import com.huc.rabbit.mq.provider.RabbitSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@SpringBootApplication
public class SpringbootRabbitmqApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootRabbitmqApplication.class, args);
    }


//    @Autowired
//    private TopicMessageProvider provider;

    @Autowired
    private PushSubMessageProvider pushSubMessageProvider;

    @Autowired
    private P2PMessageProvider p2PMessageProvider;

    @Autowired
    private ChannelMessageProvider channelMessageProvider;

    @Autowired
    private ChannelMessageConsumer channelMessageConsumer;

    @Autowired
    private RabbitSender rabbitSender;

    //    @RequestMapping("send")
//    public void send(){
//        System.out.println("发送消息");
//        String msg = String.valueOf(new Random().nextInt(1000000));
//        provider.send(msg);
//    }
    @RequestMapping("send")
    public void send() {
        String msg = String.valueOf(new Random().nextInt(1000000));
        rabbitSender.sendIngateQueue(msg);
    }


    @RequestMapping("push")
    public void push() {
        System.out.println("发布订阅发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        pushSubMessageProvider.send(msg);
    }

    @RequestMapping("p2p")
    public void p2p() {
        System.out.println("点对点发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        p2PMessageProvider.send(msg);
    }

    @RequestMapping("p2p4")
    public void p2p4() {
        System.out.println("点对点发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        p2PMessageProvider.send4(msg);
    }

    @RequestMapping("p2p2")
    public void p2p2() {
        System.out.println("点对点发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        p2PMessageProvider.send2(msg);
    }


    @RequestMapping("p2p3")
    public void p2p3() {
        System.out.println("点对点发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        p2PMessageProvider.send3(msg);
    }

    @RequestMapping("test1")
    public void test1() {
        System.out.println("点对点发送消息");
        String msg = String.valueOf(new Random().nextInt(1000000));
        p2PMessageProvider.test1(msg);
    }

    @RequestMapping("channel")
    public void channel() {
        String msg = String.valueOf(new Random().nextInt(1000000));
        channelMessageProvider.send(msg);
    }

    @Override
    public void run(String... args) throws Exception {
//        channelMessageConsumer.batchConsumer();
    }
}
